package com.lfd.jvm.pojo;

/**
 * @项目名： spring-emq
 * @包名： com.lfd.jvm.pojo
 * @文件名: CustomClassLoader
 * @创建者: liufudong@szyh-smart.com
 * @创建时间: 2024/10/14 21:25
 * @描述：
 */
public class CustomClassLoader extends ClassLoader {
    @Override
    protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
        // 先尝试委派给父类加载器

        try {
            System.out.println("loadClass: " + name+"resolve:"+resolve);
            return super.loadClass(name, resolve);
        } catch (Exception e) {
            System.out.println("Class not found by parent, loading class: " + name);

            e.printStackTrace();
            throw new ClassNotFoundException();
        }
    }

    public static void main(String[] args) throws ClassNotFoundException {
        CustomClassLoader loader = new CustomClassLoader();
        Class<?> testClass = loader.loadClass("com.lfd.jvm.pojo.TestClass");
        System.out.println("====testClass.getClassLoader()" + testClass.getClassLoader());
    }
}
